package com.example.xjtuse_pc.mobilesafe.AppLock;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.xjtuse_pc.mobilesafe.R;

public class EnterPwdActivity extends Activity {
    private EditText et_app_password;
    private ImageView iv_app_pic;
    private TextView tv_app_name1;
    private String  packname;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_enter_pwd);
        et_app_password= (EditText) findViewById(R.id.et_app_password);
        iv_app_pic= (ImageView) findViewById(R.id.iv_app_pic);
        tv_app_name1= (TextView) findViewById(R.id.tv_app_name1);
        Intent in=getIntent();
        packname = in.getStringExtra("packname");
        PackageManager pm=getPackageManager();
        try {
           ApplicationInfo af= pm.getApplicationInfo(packname, 0);
            tv_app_name1.setText(af.loadLabel(pm));
            iv_app_pic.setImageDrawable(af.loadIcon(pm));

        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

    }


    @Override
    public void onBackPressed() {

       Intent inte=new Intent();
        inte.setAction("android.intent.action.MAIN");
        inte.addCategory("android.intent.category.HOME");
        inte.addCategory("android.intent.category.DEFAULT");
        inte.addCategory("android.intent.category.MONKEY");
        startActivity(inte);
    }

    @Override
    protected void onStop() {

        super.onStop();
        finish();
    }

    public void ENTER(View view) {

        String pwd=et_app_password.getText().toString();
        Toast.makeText(this,pwd,Toast.LENGTH_SHORT).show();
        if(TextUtils.isEmpty(pwd)){
            Toast.makeText(this,"密码不能为空",Toast.LENGTH_SHORT).show();
        }
        if("123".equals(pwd)){
            //自定义广播 占时停止刷新

            Intent intent=new Intent();
            intent.setAction("com.example.xjtuse.moblesafe.tempstop");
            intent.putExtra("packname",packname);
            sendBroadcast(intent);
            finish();
        }else {
            Toast.makeText(this,"密码不正确",Toast.LENGTH_SHORT).show();;
        }
    }
}
